﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity.ModelConfiguration;
using System.Data;

namespace CMSApplication.Models.Mapping
{
    /// <summary>
    /// Needs a non-entity framework db connection to avoid pulling resources from the db unnecessarily
    /// </summary>
    public class ResourceMap : EntityTypeConfiguration<ResourceModel>
    {
        public ResourceMap()
        {
            this.HasKey(t => t.ID);

            this.ToTable("Resources");
            this.Property(t => t.SiteId)
                .HasColumnName("site_id")
                .HasColumnType(SqlDbType.Int.ToString())
                .IsRequired();
            this.Property(t => t.FileName)
                .HasColumnName("file_name")
                .HasColumnType(SqlDbType.VarChar.ToString());
            this.Property(t => t.MimeType)
                .HasColumnName("content_type")
                .HasColumnType(SqlDbType.VarChar.ToString());
            this.Property(t => t.Stream)
                .HasColumnType(SqlDbType.Image.ToString())
                .HasColumnName("resource");
        }
    }
}